package com.esdk.sql.datasource;

import com.esdk.esdk;
import com.esdk.sql.SQLRuntimeException;
import com.esdk.utils.EasyProp;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;

public class FileConnectionPool{
	private static EasyProp easyProp=esdk.prop;
	private static IConnectionPool connectionPool;

  static{
    try{
			if(!easyProp.containsKey("jdbc.url")){
				easyProp=new EasyProp("db.properties","application.properties");
			}
      connectionPool=ConnectionPoolBuilder.createPool(easyProp);
    }catch(Exception e){
      throw new SQLRuntimeException(e);
    }
  }

	public static Connection getConnection(){
		return connectionPool.getConnection();
	}

	public static DataSource getDataSource(){
		return connectionPool.getDataSource();
	}

	public static void closeConnection(){
		connectionPool.closeConnection();
	}

	public static void close() throws IOException{
		connectionPool.close();
	}
}

